#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int Mod=998244353;
const int Maxn=5010;
int n,a[Maxn],f[Maxn][Maxn];
// f{i,j} 前 i 个,前 j 个颜色方案数
int L[Maxn],R[Maxn];

int main(){
    freopen("after.in","r",stdin);
    freopen("after.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);

    for(int i=1;i<=n;i++){
        int l=i,r=i;
        while(l>1 and a[l-1]<=a[i]) l--;
        while(r<n and a[r+1]<=a[i]) r++;
        L[a[i]]=l,R[a[i]]=r;
    }

    f[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(L[j]<=i and i<=R[j]){
                for(int k=L[j]-1;k<=i;k++){
                    ll l=0;
                    for(int u=1;u<=n;u++) l+=f[k][u];
                    f[i][j]=(f[i][j]+l-f[k][j])%Mod;
                }
                    
            }
        }
    }

    // for(int i=1;i<=n;i++) cout<<i<<" "<<f[n][i]<<endl;
    // for(int i=1;i<=n;i++)
    //     for(int j=1;j<=n;j++)
    //         cout<<i<<' '<<j<<" "<<f[i][j]<<endl;

    printf("%d",f[n][n]);

    system("pause");

    return 0;
}
/*
3
1 3 2
*/